package com.liyao.storehouse.controller;

import com.liyao.storehouse.pojo.intelligence.goodsListExcel;
import com.liyao.storehouse.pojo.intelligence.inOutLogExcel;
import com.liyao.storehouse.pojo.intelligence.receiveLogExcel;
import com.liyao.storehouse.service.intelligenceService;
import com.liyao.storehouse.service.logService;
import com.liyao.storehouse.utils.ExcelUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

@Controller
@RequestMapping("/intelligence")
public class intelligenceController {
    @Resource
    intelligenceService service;

    @RequestMapping("/getToolReceiveLogList")
    @ResponseBody
    public JSONObject getToolReceiveLogList(int page, int limit){
        return service.getToolReceiveLogList(page,limit);
    }

    @RequestMapping("/getInOutLogList")
    @ResponseBody
    public JSONObject getInOutLogList(int page, int limit) {
        return service.getInOutLogList(page, limit);
    }

    @RequestMapping("/getGoodsList")
    @ResponseBody
    public JSONObject getGoodsList(int page, int limit) {
        return service.getGoodsList(page, limit);
    }

    @RequestMapping("/SearchToolReceiveLogList")
    @ResponseBody
    public JSONObject SearchToolReceiveLogList(int page, int limit,String partDes,String location,String userName) {
        return service.SearchToolReceiveLogList(page, limit,partDes,location,userName);
    }

    @RequestMapping("/SearchGoodsList")
    @ResponseBody
    public JSONObject SearchGoodsList(int page, int limit, String partDes, String location, String partNo) {
        return service.SearchGoodsList(page, limit, partDes, location, partNo);
    }

    @RequestMapping("/SearchInOutLogList")
    @ResponseBody
    public JSONObject SearchInOutLogList(int page, int limit, String partDes, String location, String userName, String onShelf) {
        return service.SearchInOutLogList(page, limit, partDes, location, userName,onShelf);
    }

    @RequestMapping("/outGravityCabinetToolExcel")
    @ResponseBody
    public void outGravityCabinetToolExcel(HttpServletResponse response,String partDes,String location,String userName) throws IOException {
        List<receiveLogExcel> list=service.outGravityCabinetToolExcel(partDes,location,userName);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode("领用记录", "UTF-8")+".xlsx");
        ExcelUtil.writeExcel(response,list,"领用记录", receiveLogExcel.class);
    }

    @RequestMapping("/outInOutLogExcel")
    @ResponseBody
    public void outInOutLogExcel(HttpServletResponse response, String partDes, String location, String userName, String onShelf) throws IOException {
        List<inOutLogExcel> list = service.outInOutLogExcel(partDes, location, userName,onShelf);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("上下架记录", "UTF-8") + ".xlsx");
        ExcelUtil.writeExcel(response, list, "上下架记录", inOutLogExcel.class);
    }

    @RequestMapping("/outGoodsExcel")
    @ResponseBody
    public void outGoodsExcel(HttpServletResponse response, String partDes, String location, String partNo) throws IOException {
        List<goodsListExcel> list = service.outGoodsExcel(partDes, location, partNo);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("商品信息", "UTF-8") + ".xlsx");
        ExcelUtil.writeExcel(response, list, "商品信息", goodsListExcel.class);
    }
}
